route.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { NextRequest, NextResponse } from 'next/server';
  2. // 정적 리소스 호스트 (배너/팝업/회원 사진/게시판 이미지 등).
  3. // 로컬: NEXT_PUBLIC_RESOURCE_URL 미설정 시 API_URL 로 폴백 (API 가 wwwroot 정적 서빙).
  4. // dev/prod: dev-resource.antooza.com / resource.antooza.com 가 Admin/API uploads 통합 서빙.
  5. const RESOURCE_URL = process.env.NEXT_PUBLIC_RESOURCE_URL || process.env.API_URL;
  6. export async function GET(_: NextRequest, { params }: { params: Promise<{ path: string[] }> })
  7. {
  8. const { path } = await params;
  9. const filePath = `/uploads/${path.join('/')}`;
  10. try {
  11. const res = await fetch(`${RESOURCE_URL}${filePath}`, {
  12. cache: 'no-store'
  13. });
  14. if (!res.ok) {
  15. return new NextResponse(null, {
  16. status: res.status
  17. });
  18. }
  19. const contentType = res.headers.get('content-type') || 'application/octet-stream';
  20. const buffer = await res.arrayBuffer();
  21. return new NextResponse(buffer, {
  22. status: 200,
  23. headers: {
  24. 'Content-Type': contentType,
  25. 'Cache-Control': 'public, max-age=31536000, immutable'
  26. }
  27. });
  28. } catch {
  29. return new NextResponse(null, {
  30. status: 502
  31. });
  32. }
  33. }